@extends('admin.layouts.app')
@section('content')

                        <!-- Page-Title -->
                        <div class="row">
                            <div class="col-sm-12">
                                <h4 class="page-title">车系管理</h4>
                                <ol class="breadcrumb">
                                    <li><a href="{{url('zadmin')}}">系统</a></li>
                                   
                                    <li class="active">车系列表</li>
                                </ol>
                            </div>
                        </div>
                        
                        <div class="row">
                        	<div class="col-lg-12">
                        		<div class="card-box">
                        			<div class="row">
			                        	<div class="col-sm-8">
			                        		<form role="form">
			                                    <div class="form-group contact-search m-b-30 col-sm-8">
			               <input type="text" id="search" class="form-control" value="{{array_get($param,'keyword')}}" name="keyword">
                                          </div>
                                          <div class="col-sm-4">  
			                                        <button type="submit" class="btn btn-white"><i class="fa fa-search"></i></button>
			                                    </div> <!-- form-group -->
			                                </form>
			                        	</div>
			                        	<div class="col-sm-4">
			                        		

                                  <a href="#custom-modal" class="btn btn-primary btn-md waves-effect waves-light m-b-30" data-animation="fadein" data-plugin="custommodal" 
                                                            data-overlaySpeed="200" data-overlayColor="#36404a"><i class="md md-add"></i>添加</a>
			                        	</div>
			                        </div>

                              @if(session('rs'))
                              <div class="alert alert-{{session('rs')['status']}}">
                                {{ session('rs')['msg'] }}
                              </div>
                              @endif
			                        
                        			<div class="table-responsive">
                                        <table class="table table-hover">
                                        	<thead>
												<tr>
													<th style="min-width: 35px;">
													ID
                                                        
													</th>
                          <th>所属品牌</th>
													<th>所属车系</th>
                        
                          <th>车型</th>
													
                         
                         
													<th style="width: 200px;">操作</th>
												</tr>
											</thead>
											
                                            <tbody>

                                            @foreach($list as $v)
                                                <tr>
                                                    <td>
                                                        {{$v->id}}
                                                        
                                                      
                                                    </td>
                                                    
                                                    <td>
                                                        {{object_get($v,'brand.name')}}
                                                    </td>
                                                    <td>
                                  {{object_get($v,'serie.name')}}</td>
                                                    <td>
                                  {{$v->name}}
                                                    </a>  
                                                    </td>
                                                    
                                                    
                                                    
                                                
                                                    
                                                   
                                                    <td>
        <a href="{{url('zadmin/car-models/'.$v->id.'/edit')}}" ><i class="md md-edit"></i>编辑</a>
        <a href="{{url('zadmin/car-models',$v->id)}}" data-method="delete" 
  data-token="{{csrf_token()}}" data-confirm="确定删除吗?"><i class="md md-close"></i>删除</a>
                                                    </td>
                                                </tr>
                                            @endforeach    
                                                
                                               
                                               
                                                
                                               
                                                
                                            
                                            </tbody>
                                        </table>
                                    </div>
                                    {{ $list->links() }}
                        		</div>
                                
                            </div> <!-- end col -->

                            
                        </div>
@endsection
                        
                        
                        

                  
            
    @section('modal')        
        <!-- Modal -->
      <div id="custom-modal" class="modal-demo">
          <button type="button" class="close" onclick="Custombox.close();">
              <span>&times;</span><span class="sr-only">Close</span>
          </button>
          <h4 class="custom-modal-title">添加车型</h4>
          <div class="custom-modal-text text-left">
              <form class="form-horizontal" role="form" action="{{url('zadmin/car-models')}}" method="post" enctype="multipart/form-data">                                    
                <div class="form-group">
                  <label class="col-md-2 control-label">品牌</label>
                  <div class="col-md-10">
                    <select  class="form-control select2" name="brand_id" required="" style="width:220px;" id="brand_id">
                      <option value="">请选择品牌</option>
                      @foreach($brands as $b)
                      <option value="{{$b->id}}">{{$b->name}}</option>
                      @endforeach
                    </select>
                  </div>
                </div>
                <div class="form-group">
                  <label class="col-md-2 control-label">车系</label>
                  <div class="col-md-10">
                    <select  class="form-control select2" name="series_id" required="" style="width:220px;" id="series_id">
                      <option value="">请选择车系</option>
                      
                    </select>
                  </div>
                </div>                              
                <div class="form-group">
                  <label class="col-md-2 control-label">车型名称</label>
                  <div class="col-md-10">
                    <input type="text" class="form-control" name="name" value="" required="">
                  </div>
                </div>                                                                                                    
                                              

                                              <div class="form-group text-center">
                                                  
                                                  <button type="submit" class="btn btn-info waves-effect waves-light">保存</button>
                                              </div>
                                              
                                              
                             {{csrf_field()}}
                                          </form>
          </div>
      </div>
    @endsection        
       
@section('js')
<style type="text/css">
  <style>
    /*select2在Bootstrap的modal中默认被遮盖，现在强制显示在最前*/
    .select2-drop {
        z-index: 10050 !important;
    }
 
    .select2-search-choice-close {
        margin-top: 0 !important;
        right: 2px !important;
        min-height: 10px;
    }
 
        .select2-search-choice-close:before {
            color: black !important;
        }
    /*防止select2不会自动失去焦点*/
    .select2-container {
        z-index: 16000 !important;
    }
 
    .select2-drop-mask {
        z-index: 15990 !important;
    }
 
    .select2-drop-active {
        z-index: 15995 !important;
    }
</style>
     <script type="text/javascript">
      $('.select2').select2({
        placeholder: "--请选择--",
        dropdownParent: $("#custom-modal"),
        allowClear: true
      });
      $('#brand_id').on('change',function(){
          var _this    = $(this);
    var brand_id = _this.val();
    var url = "{{url('api/car-series')}}";
       
     $.get(url,{'brand_id':brand_id},function(rs){
            if(rs.status==true) {
                var service = $('#series_id');
                service.empty();
                var opt = '';
                $.each(rs.data,function(k,v){
                    opt += '<option value="'+v.id+'">'+v.name+'</option>'; 
                });
                 service.append(opt);
                
            }
        })
      });
     </script>   
@endsection  



    
        
    
